﻿using System.Data.SQLite;
using System.IO;
using System.Windows;
using WpfApp1.View;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private static string source = Directory.GetCurrentDirectory() + @"\train_tools.sqlite";
        public static SQLiteConnection connecttion = new SQLiteConnection("Data Source=" + source);

        public MainWindow()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
            if (connecttion.State != System.Data.ConnectionState.Open)
            {
                connecttion.Open();
            }
        }

        private void Btn_train_Click(object sender, RoutedEventArgs e)
        {
            Train train = new Train();
            train.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            train.Show();
        }

        private void CloseWindow(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (connecttion.State == System.Data.ConnectionState.Open)
            {
                connecttion.Close();
            }
        }

        private void Trip_ist(object sender, RoutedEventArgs e)
        {
            Trip trip = new Trip
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };
            trip.Show();
        }

        // 计算器
        private void Calculator_Click(object sender, RoutedEventArgs e)
        {
            Window cal = new Calculator() {
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            cal.Show();
        }
    }
}
